from pyeasyaccept.commands.ExpectBetweenCommand import ExpectBetweenCommand
from pyeasyaccept.commom.Configuration import Configuration
from pyeasyaccept.script.ParsedLineReader import ParsedLineReader
from pyeasyaccept.script.Script import Script
import unittest
import os
from pythoneasyaccept_test.TestFacade import TestFacade

"""
This class tests the 'expectBetween' command
@author: Artur Farias
"""
class ExpectBetweenCommandTest(unittest.TestCase):
    
    configuration = Configuration.getInstance()
    
    """
    This method sets initial information
    """
    def setUp(self):
        self.FILE_SEPARATOR = Configuration.FILE_SEPARATOR          
        self.root = self.configuration.getProjectRoot()
        
    """
    This method tear down informations
    """
    def tearDown(self):
        pass

    """
    This method runs the successful tests
    """
    def testExpectBetweenCommand(self):
        testExpectBetweenCommand1 = self.root + self.configuration.TEST_SCRIPTS_LOCATION + os.sep+"TestExpectBetween1.txt"        
         
        parsedLineReader = ParsedLineReader(testExpectBetweenCommand1)
        
        testFacade = TestFacade()
        script = Script(testFacade, testExpectBetweenCommand1)
        
        parsedLine1 = parsedLineReader.getParsedLine()
        parsedLine2 = parsedLineReader.getParsedLine()
        parsedLine3 = parsedLineReader.getParsedLine()
        parsedLine4 = parsedLineReader.getParsedLine()
        
        resultLine1 = script.executeCommand(parsedLine1)
        resultLine2 = script.executeCommand(parsedLine2)
        resultLine3 = script.executeCommand(parsedLine3)
        resultLine4 = script.executeCommand(parsedLine4)
        
        self.assertEquals(Configuration.SUCCESS_CODE, resultLine1.getTestLineStatus())
        self.assertEquals(Configuration.SUCCESS_CODE, resultLine2.getTestLineStatus())
        self.assertEquals(Configuration.SUCCESS_CODE, resultLine3.getTestLineStatus())
        self.assertEquals(Configuration.SUCCESS_CODE, resultLine4.getTestLineStatus())

    """
    This method runs the error tests
    """
    def testExpectBetweenCommandError(self):
        testExpectBetweenCommandError = self.root + self.configuration.TEST_SCRIPTS_LOCATION + os.sep+"TestExpectBetweenError1.txt"        
         
        parsedLineReader = ParsedLineReader(testExpectBetweenCommandError)
        testFacade = TestFacade()
        script = Script(testFacade, testExpectBetweenCommandError)
        
        parsedLine1 = parsedLineReader.getParsedLine()
        parsedLine2 = parsedLineReader.getParsedLine()
        parsedLine3 = parsedLineReader.getParsedLine()
        parsedLine4 = parsedLineReader.getParsedLine()
        
        resultLine1 = script.executeCommand(parsedLine1)
        resultLine2 = script.executeCommand(parsedLine2)
        resultLine3 = script.executeCommand(parsedLine3)
        resultLine4 = script.executeCommand(parsedLine4)
        
        self.assertEquals(Configuration.ERROR_CODE, resultLine1.getTestLineStatus())
        self.assertEquals(Configuration.ERROR_CODE, resultLine2.getTestLineStatus())
        self.assertEquals(Configuration.ERROR_CODE, resultLine3.getTestLineStatus())
        self.assertEquals(Configuration.ERROR_CODE, resultLine4.getTestLineStatus())
        
        self.assertEquals("The result: \"5.0\" is not between [10.0,100.0]", resultLine1.getErrorMessage())
        self.assertEquals("The result: \"110.1234\" is not between [10.93,100.24]", resultLine2.getErrorMessage())
        self.assertEquals("All the parameters should be float numbers.", resultLine3.getErrorMessage())
        self.assertEquals("All the parameters should be float numbers.", resultLine4.getErrorMessage())
        
        
    
if __name__ == '__main__':
    unittest.main() 